const express = require('express');
const db = require('../db/index')

const router = express.Router();

// 定义接口
// 获取资讯列表
// http://127.0.0.1:3006/news/information
router.get('/information', (req, res) => {
    const sql = 'select * from news';
    db.query(sql, (err, result) => {
        if (err) return res.lose(err)
        res.send({
            message: '获取资讯数据成功',
            success: true,
            status: 0,
            result
        })
    })
})
// 根据id查询 资讯 http://127.0.0.1:3006/news/getDetail?id=1
router.get('/getDetail', (req, res) => {
    const id = Number(req.query.id);
    const sql = 'select * from news where id=?';
    db.query(sql, [id], (err, result) => {
        if (err) return res.lose(err)
        res.send({
            message: '根据id获取资讯数据成功',
            success: true,
            status: 0,
            result
        })
    })
})

module.exports = router;